package com.hydl.power.controller;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.github.pagehelper.PageInfo;
import com.hydl.power.aop.annotation.LogAnnotation;
import com.hydl.power.mapper.LoadMapper;
import com.hydl.power.pojo.Identical;
import com.hydl.power.pojo.Load;
import com.hydl.power.service.LoadService;
import com.hydl.power.utils.EasyPoiUtil;
import com.hydl.power.utils.Resp;
import com.hydl.power.utils.TableUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.text.ParseException;
import java.util.List;


/**
 * @author wxb
 * @date 2019/12/28 10:48
 */
@RestController
@RequestMapping("/load")
@Api(value = "LoadController",tags = "负荷分析")
@CrossOrigin
/**
 * 负荷分析Load analysis
 */
public class LoadController {
    @Autowired
    private LoadService loadService;

    @Autowired
    private LoadMapper loadmapper;

    //@LogAnnotation(module = "负荷分析",description = "负荷分析list分页")
    @PostMapping(value = "/getAllLoadByPage")
    @ApiOperation(value = "负荷分析list分页",produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "pageNum", value = "页数",required = true,  dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "条数",required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "startTime", value = "开始时间", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "deviceId", value = "设备Id", dataType = "String"),
    })
    public Resp getLoad(Integer pageNum, Integer pageSize, String startTime, String deviceId) throws ParseException {
        return Resp.success(loadService.queryLoads(pageNum,pageSize,startTime,deviceId));
    }


    // @LogAnnotation(module = "负荷分析",description = "负荷分析导出Excel")
    @ApiOperation(value = "负荷分析导出Excel（废弃）" ,produces = "application/json")
    @GetMapping(value = "/excelLoad")
    @ApiImplicitParams({
      @ApiImplicitParam(paramType = "query", name = "pageNum", value = "页数",required = true,  dataType = "String"),
      @ApiImplicitParam(paramType = "query", name = "pageSize", value = "条数",required = true, dataType = "String"),
      @ApiImplicitParam(paramType = "query", name = "startTime", value = "开始时间", dataType = "String"),
      @ApiImplicitParam(paramType = "query", name = "deviceId", value = "设备Id", dataType = "String"),
    })
    public void IdenticalExport(HttpServletResponse response,Integer pageNum, Integer pageSize, String startTime, String deviceId) throws Exception {
        String fileName="负荷分析";
        PageInfo<Load> list = loadService.queryLoads(pageNum,pageSize,startTime,deviceId);
        List<Load> arr = list.getList();
        EasyPoiUtil.exportExcel(EasyPoiUtil.getWorkbook(fileName, fileName, Load.class, arr), fileName, response);
    }

}
